<?php

class Home  extends PageBase {

	public function onInit($param){
		parent::onInit($param);
		$this->dgDatos->DataSource =CajachicaPeer::CajachicaHome();
		$this->dgDatos->dataBind();
	}

	public function dgDatos_OnPageIndexChanged($sender,$param){
		$this->dgDatos->CurrentPageIndex	= 	$param->NewPageIndex;
		$pageSize 							= 	$this->dgDatos->PageSize;
		$offset 							= 	$param->NewPageIndex*$pageSize;
		$this->dgDatos->DataSource 			= 	$this->Bind($offset, $pageSize);
		$this->dgDatos->dataBind();
	}

	public function dgDatos_OnPagerCreated($sender,$param){
		$style			=	$param->Pager->DataGrid->getPagerStyle();
		$pageCount		=	$param->Pager->DataGrid->getPageCount();
		$pageIndex		=	$param->Pager->DataGrid->getCurrentPageIndex()+1;
		$maxButtonCount	=	$style->getPageButtonCount();
		$buttonCount	=	(($maxButtonCount > $pageCount) ? $pageCount : $maxButtonCount);
		$startPageIndex	=	1;
		$endPageIndex	=	$buttonCount;

		if($pageIndex > $endPageIndex){
			$startPageIndex	=	((int)(($pageIndex - 1) / $maxButtonCount)) * $maxButtonCount + 1;

			if(($endPageIndex = $startPageIndex + $maxButtonCount - 1) > $pageCount){
				$endPageIndex	=	$pageCount;
			}

			if($endPageIndex - $startPageIndex + 1 < $maxButtonCount){
				if(($startPageIndex = $endPageIndex - $maxButtonCount + 1) < 1){
					$startPageIndex	=	1;
				}
			}
		}

		//	$param->Pager->Controls->insertAt(0,"P&aacute;gina " . $startPageIndex . " a " . $endPageIndex . " de " . $pageCount . ": ");
	}

	protected function Bind($offset, $rows){
		$filtro = $this->txtBusqueda->Text;
		$this->dgDatos->DataSource = CajachicaPeer::CajachicaHome($filtro);
		$this->dgDatos->dataBind();
	}

	public function btnBuscar_OnClick($sender, $param){
		$this->Bind(0, $this->dgDatos->PageSize);
		if($this->dgDatos->Items->Count>0){
			$this->lblBusqueda->Text = "";
		}
		else{
			$this->lblBusqueda->Text = "No se han encontrado datos para la consulta especificada.";
		}
	}

}
?>